<template>
  <div class="table-page">
    <GiTable
      row-key="id"
      title="商铺认证管理"
      :data="dataList"
      :columns="columns"
      :loading="loading"
      :scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
      :pagination="pagination"
      :disabled-tools="['size']"
      :disabled-column-keys="['name']"
      @refresh="search"
    >
      <template #custom-left>
	        <a-input v-model="queryForm.name" placeholder="请输入法人姓名" allow-clear @change="search">
	          <template #prefix><icon-search /></template>
	        </a-input>
	        <a-input v-model="queryForm.personId" placeholder="请输入身份证号码" allow-clear @change="search">
	          <template #prefix><icon-search /></template>
	        </a-input>
	        <a-select
	          v-model="queryForm.status"
	          :options="status_enum"
	          placeholder="请选择审核状态"
	          allow-clear
	          style="width: 150px"
	          @change="search"
	        />
        <a-button @click="reset">重置</a-button>
      </template>
      <template #custom-right>
        <a-button v-permission="['system:personShopIdentification:add']" type="primary" @click="onAdd">
          <template #icon><icon-plus /></template>
          <span>新增</span>
        </a-button>
        <a-tooltip content="导出">
          <a-button v-permission="['system:personShopIdentification:export']" class="gi_hover_btn-border" @click="onExport">
            <template #icon>
              <icon-download />
            </template>
          </a-button>
        </a-tooltip>
      </template>
      <template #name="{ record }">
        <a-link @click="onDetail(record)">{{ record.name }}</a-link>
      </template>
      <template #action="{ record }">
        <a-space>
          <a-link v-permission="['system:personShopIdentification:update']" @click="onUpdate(record)">修改</a-link>
          <a-link
            v-permission="['system:personShopIdentification:delete']"
            status="danger"
            :disabled="record.disabled"
            @click="onDelete(record)"
          >
            删除
          </a-link>
        </a-space>
      </template>
    </GiTable>

    <PersonShopIdentificationAddModal ref="PersonShopIdentificationAddModalRef" @save-success="search" />
    <PersonShopIdentificationDetailDrawer ref="PersonShopIdentificationDetailDrawerRef" />
  </div>
</template>

<script setup lang="ts">
import PersonShopIdentificationAddModal from './PersonShopIdentificationAddModal.vue'
import PersonShopIdentificationDetailDrawer from './PersonShopIdentificationDetailDrawer.vue'
import { type PersonShopIdentificationQuery, type PersonShopIdentificationResp, deletePersonShopIdentification, exportPersonShopIdentification, listPersonShopIdentification } from '@/apis'
import type { TableInstanceColumns } from '@/components/GiTable/type'
import { useDownload, useTable } from '@/hooks'
import { isMobile } from '@/utils'
import has from '@/utils/has'
import { useDict } from '@/hooks/app'

defineOptions({ name: 'PersonShopIdentification' })

const queryForm = reactive<PersonShopIdentificationQuery>({
  name: undefined,
  personId: undefined,
  status: undefined,
  sort: ['createTime,desc']
})

const { status_enum } = useDict('status_enum')

const {
  tableData: dataList,
  loading,
  pagination,
  search,
  handleDelete
} = useTable((page) => listPersonShopIdentification({ ...queryForm, ...page }), { immediate: true })

const columns: TableInstanceColumns[] = [
  { title: '企业名称', dataIndex: 'companyName', slotName: 'companyName' },
  { title: '企业税号', dataIndex: 'companyTax', slotName: 'companyTax' },
  // { title: '银行卡号', dataIndex: 'cardNo', slotName: 'cardNo' },
  // { title: '开户行支行地址', dataIndex: 'bankAddress', slotName: 'bankAddress' },
  { title: '法人证件', dataIndex: 'name', slotName: 'name' },
  { title: '身份证号码', dataIndex: 'personId', slotName: 'personId' },
  // { title: '支付宝账号', dataIndex: 'alipayNo', slotName: 'alipayNo' },
  { title: '店铺名称', dataIndex: 'shopName', slotName: 'shopName' },
  // { title: '主营类目', dataIndex: 'businessCategory', slotName: 'businessCategory' },
  // { title: '营业执照副本', dataIndex: 'businessLicense', slotName: 'businessLicense' },
  // { title: '法人身份证正面', dataIndex: 'passportFaceImg', slotName: 'passportFaceImg' },
  // { title: '法人身份证背面', dataIndex: 'passportSideImg', slotName: 'passportSideImg' },
  // { title: '法人身份证手持', dataIndex: 'passportHandImg', slotName: 'passportHandImg' },
  // { title: '公户银行卡正面', dataIndex: 'bankcardFront', slotName: 'bankcardFront' },
  // { title: '公户银行卡背面', dataIndex: 'bankcardEnd', slotName: 'bankcardEnd' },
  { title: '审核状态', dataIndex: 'status', slotName: 'status' },
  { title: '创建时间', dataIndex: 'createTime', slotName: 'createTime' },
  {
    title: '操作',
    slotName: 'action',
    width: 130,
    align: 'center',
    fixed: !isMobile() ? 'right' : undefined,
    show: has.hasPermOr(['system:personShopIdentification:update', 'system:personShopIdentification:delete'])
  }
]

// 重置
const reset = () => {
  queryForm.name = undefined
  queryForm.personId = undefined
  queryForm.status = undefined
  search()
}

// 删除
const onDelete = (item: PersonShopIdentificationResp) => {
  return handleDelete(() => deletePersonShopIdentification(item.id), {
    content: `是否确定删除该条数据？`,
    showModal: true
  })
}

// 导出
const onExport = () => {
  useDownload(() => exportPersonShopIdentification(queryForm))
}

const PersonShopIdentificationAddModalRef = ref<InstanceType<typeof PersonShopIdentificationAddModal>>()
// 新增
const onAdd = () => {
  PersonShopIdentificationAddModalRef.value?.onAdd()
}

// 修改
const onUpdate = (item: PersonShopIdentificationResp) => {
  PersonShopIdentificationAddModalRef.value?.onUpdate(item.id)
}

const PersonShopIdentificationDetailDrawerRef = ref<InstanceType<typeof PersonShopIdentificationDetailDrawer>>()
// 详情
const onDetail = (item: PersonShopIdentificationResp) => {
  PersonShopIdentificationDetailDrawerRef.value?.onDetail(item.id)
}
</script>

<style lang="scss" scoped></style>
